import QrCode from './qrcode';

export class QRCodeUtils {
  static gen(data: Uint8Array): Uint8Array {
    const qrcode = new QrCode('', {
      width: 200,
      height: 200,
      correctLevel: QrCode.CorrectLevel.L,
      text: data,
    });
    const obj = qrcode as object
    const modules = obj['code']['modules']
    const length = modules.length;
    const array = []
    for (let i = 0; i < modules.length; i++) {
      for (let j = 0; j < modules[i].length; j++) {
        if (modules[i][j]) {
          array.push(0x00)
          array.push(0x00)
          array.push(0x00)
          array.push(0xFF)
        } else {
          array.push(0xFF)
          array.push(0xFF)
          array.push(0xFF)
          array.push(0xFF)
        }
      }
    }
    return new Uint8Array(array)
  }
}

